C^v^gp}jA

C^v^WindowsLinuxłقړ悤ɍ쐬Ă܂B
JC++łB


Linux    J     gcc 3.4.4
Windows  J     VisualC++6

Windowsł̃RpC@
basic.dsw@VisualC++6ȏŊJĂ

Linuxł̃RpC@
c++LłȂƃRpCł܂
make R}hsĂ




N@

basic filename

ɃC^v^ŎsvȌꂽeLXgt@CnƂɂsł܂



s̍s
vO͈s̕ftHg1024ȓłKv܂B
܂AϐɊi[\ȍő啶ftHg1024ȓłKv܂B
ύXɂ́A
common.h@́@#define MAX_STR_LEN 1024@ύXKv܂B


vOŎgp\ȕϐ

ϐ^64rbg_^ƕ^܂B
ϐсAϐ^̐錾͕Kv܂B

wȂ̏ꍇ̓O[oXR[v܂
֐̈ƂĎw肳Ăϐ́A֐̃XR[v܂

ź@data[1]@̂悤Ɏw肵܂B
ź@data[1][2]@̂悤Ɏw肵܂̐͂܂B

ȉ̂悤ɔz̓YƂĕw肷邱Ƃł܂
data["aaa"]=1


sɂ킽閽

s \ ƓǂݍݎɎ̍sƘA܂


Ɛl̉Z

̑Zsꂽꍇ͕񂪘AA
lm̉Zsꂽꍇɂ́Al̉Zʂ߂܂B
lƕ̑ZsꂽꍇɂẮAlƂĈAƂĘA܂B

vO
print 1+1
print 1+"test"
print "test"+1
print "test"+"test"

s
$ ./basic test.txt
2
1test
test1
testtest


vOŎgp\Ȗ

Rg

'Rg

'Ŏn܂镶̓RgƂĈ܂




̂P
sŏꍇ

if  then ߂P else ߂Q

̌ʂ0̏ꍇ͖߂QsAȊOɂ͖߂Ps܂
j߂PA߂Q@̉ӏ if  eval ߂͋Lqł܂B

Eɂ͈ȉ̂̂gpł܂

==	CR[
<	ȂȂ
>	Ȃ菬Ȃ
<=	ȂȂCR[
>=	Ȃ菬ȂCR[
&&	Ah
||	IA
<>	mbgCR[


ẼTv
if 1==1 then print "true" else print "false"
if "test"=="test" then print "true" else print "false"
if 1<1 then print "true" else print "false"
if 1>1 then print "true" else print "false"
if 1<=1 then print "true" else print "false"
if 1>=1 then print "true" else print "false"
if 1==1 && 2==1 then print "true" else print "false"
if 1==1 || 2==1 then print "true" else print "false"
if "test"<>"aaaa" then print "true" else print "false"


̂Q
sɓnꍇ
߂͕sɂ킽菑Ƃł܂
iflXg邱Ƃł܂B

if  then
	
else
	
endif


[v

for x=1 to 10
	print x
next x

x1`10܂Ń[v܂
for̃lXg\ł


Wv

label:

goto label:

gotoɂ胉xɃWv܂
x͖߂ƂėpĂȂłA:tKv܂


֐

func '֐̌Ăяo

@func '֐{
	return
_@

֐LqƊ֐Ă΂܂Breturn߂ɂ֐̖[ɃWv܂
֐̖[ _@ ɓBƁAĂяoɕA܂

KA @֐  _@ ͈΂łKv܂B
gݖ߂ƓO̊֐쐬ꍇɂ́A֐͖܂B

֐̃[Jϐ

    @֐ ϐ1
        
        ̒ł ϐ1 [JϐɂȂ܂
        ֐ł̃XR[vĂAꖼ̕ϐƂĂO[oϐ̉e͎󂯂܂񂵁Ae܂B
        
    _@

͌ĂяoɒlnAnȂɊ֌WȂRɎwł܂B
̓J}ŋ؂邱Ƃɂ256܂Ŏwł܂B

@func a,b,c,d,e,f,g

Lła,b,c,d,e,f,g̃[Jϐw肵Ă܂B


[JϐɒlnČĂяo

func a

@funcɑ΂ĕϐ a ̒lnČĂяoĂ܂B
̒lnꍇɂ̓J}ŋ؂Ďw肵܂

func a,b,1+1,d+1

Lł a,b,1+1,d+1 ̒ln܂B


vO

a="hello"
test 0
print a
end

@test a
	print a
	if a<5 then test a+1
	print a
	return
_@


s

$ ./basic ./sample/test.txt
0
1
2
3
4
5
5
4
3
2
1
0
hello


֐̃AhX

֐͊֐̑O@邱Ƃɂ֐̃AhXo܂
܂A֐ɃAhX邱Ƃł܂B


@fu=@func '֐ func  fu ɃRs[
fu 100 '֐ fu Ă
end

@func a
	print a+1
	print "func"
	return
_@


z̊֐

@ar[1] a,b
_@

@ar["test"] a,b
_@

錾̊֐̔z̓Y̓vO̎sOɉ߂邽߁A
萔łKv܂B
Ăяo̓Y͒萔łKv͂܂

sɊ֐̌ĂяoŁA
Y̊֐Ȃꍇɂ
ꎟ̃ftHg̔z֐Ăт܂B
[]̒̊֐ftHgł̔z֐łB

@ar[] a,b
_@


֐

@@@_@@܂łubNƂĈ܂
ubNOsꂽꍇAubN͎s΂܂
̏ꍇɂ́A֐̃AhX ϐ @ ɑ܂B

֐ @ ̃AhX͎sɉ߂s܂B

@
	ubN
_@


vO

@ a,b
	print a
	print b
	return
_@

@fu=@ '֐̃AhX
fu "aaa","bbb"


s

$ ./basic ./test.txt
aaa
bbb


֐g[v
֐𗘗p邱Ƃɂ胋[vł܂
@thisɂ͊֐̐擪AhX܂

vO

@ i,j
	if i>j then return
	i=i+1
	print i
	goto @this
_@
@foo=@
foo 0,4

s

$ ./basic ./test.txt
1
2
3
4
5


֐̖߂l

֐ŕϐ this ɑꂽl߂lɂȂ܂
߂l͌Ăяo̊֐ƓO̕ϐɊi[܂B
z֐̏ꍇ @func[] ł͓YɊ֌WȂAϐ func Ɋi[܂

vO

@test a,b
	this=a+b '߂lݒ
_@

@func=@test '֐Rs[
func 2,3
print func

s

$ ./basic ./test.txt
5


֐ɓnꂽϐ擾

֐ɓnꂽڂ͕̈ϐ # Ɋi[Ă܂B
𗘗p邱Ƃɂ̕ϐ̒lύX邱Ƃł܂B

vO

@func a,b
	eval #+"=\"aaaa\""
_@

test=0
test2=0
func test,test2 '֐Ă
print test


s

$ ./basic test.txt
aaaa


͖

input ϐ

͂v܂A͌ʂϐɊi[܂


o͖

print ""
print ϐ

lʏɏo͂܂


GXP[vV[PX
GXP[vV[PXΉ̒[̂ݑΉ܂

clr
location 1,1

clr߂ɂʂNA܂
location߂ɂJ[\ʂ̎wWɈړ܂


ҋ@

wait

̖߂ƁA1bԃvO~܂


abs

abs ϐ

ϐɊi[ĂĺA_ȉ؂̂ĂāA
absƂϐɌʂi[܂B


shell

shell "notepad test.txt"

w肵vOs܂
svOI܂őҋ@܂


I

end

̖߂ǂݍ܂ꂽ_ŃvOI܂


vOŎgp\Ȋϐ

͏o܂AQƂ݂̂łB
ʏ̕ϐ̂悤ɓǂݏo܂B


擾ł闐ĺ@0`9999@͈̔͂ł

rand



time.year	N
time.mon	
time.day	
time.week	j0Aj1Ƃj킷l
time.hour	
time.min	
time.sec	b

R}hC̈

args[1`N] ɑ܂

\G[
vOsɍ\G[ꍇA
ԍŌɋNG[̍sio[ۑ܂B
G[̔s͎񂩂sXLbv邱Ƃ܂B

system.err.line		ԍŌɔG[sio[
system.err.msg		ԍŌɔG[bZ[W


G[̎s~

system.err.exit@ 0 ȊO̐ĂꍇȀŃvO~܂
l 0 ł


input ̃mubLO[h

system.io.inputblock 1 ȊOݒ肷ƃmubLO[hɂȂ܂
l 1 ł


GXP[v

\Ŏn܂鎟͑̕ăGXP[v܂

\"@" 
\\@\ 

A͕̕ϊ܂B

\n         s
\a         x
\x00`\xFF 16i

񑀍얽
̒𒲂ׂ

len 

ϐ len ɕ̒i[܂
L̏ꍇ 7 łB

a="abcdefg"
len a
print len


̐؂o mid

mid ,؏oJnʒu,؏o

ϐ mid ɐ؂oꂽ񂪊i[܂
؏oJnʒúA̐擪̈ʒułB
L̏ꍇł̌ʂ bcde łB

a="abcdefg"
mid a,1,4
print mid


񂩂琔lւ̕ϊ val

val ϐ

ϐ̕񂪐lɂȂ܂B
ϊłȂꍇɂ 0 ɂȂ܂B

l當ւ̕ϊ str

str ϐ

CSV`̐؏o

csv ϐ

؏oʂ́Aϐ[1]`@ɑ܂B
؏oʂ̖́@ϐ[N]ɂ "," ܂B

vO

aaa="\"aaa\",001,\"002\",ddd"
print aaa

csv aaa	'csv̐؏o

loop1:
	i=i+1
	print aaa[i]
if ","<>aaa[i] then goto loop1: '؏o̖܂Ń[v

s

$ ./basic test.txt
"aaa",001,"002",ddd
aaa
001
002
ddd
,


CSV`̍쐬

vsc ϐ,,

ϐ[1]`[N]̒lŕŁAJ}؂̕쐬܂B

 0 w肷Ɩ","܂ŏ܂B
w肳ĂĂ","ꍇɂ͎c̒l󔒂Ƃč쐬܂B
ϐ[X]ɐlĂꍇɂ́Aŕ݂܂B


vO

ar[1]="aaa"
ar[2]="bbb"
ar[3]=1
ar[4]=2
ar[5]=","
ar[6]="ccc"
ar[6]="ddd"

vsc ar,"'",10

print ar


s

$ ./basic test.txt
'aaa','bbb',1,2,'','','','','',''


Œ蒷̐؏o

chop ϐ,؏oz

؏oʂ́Aϐ[1]`@ɑ܂B
؏oʂ̖́@ϐ[N]ɂ "," ܂B

؏ozɂ́A
ϐ[1]`@ɐ؂oĂB


vO

ar="5,4,3" '5@4@3@cS ɐ؂o܂
csv ar 'csv߂𗘗pz쐬܂B
data="abcdefghijklmnopqrstuvwxyz"

chop data,ar

loop:
	i=i+1
	str=data[i]
	print str
if str<>"," then goto loop: '؏o̖܂Ń[v


s

$ ./basic test.txt
abcde
fghi
jkl
mnopqrstuvwxyz
,


trim

̑ÕXy[X菜܂B
ʂ͓nϐɊi[܂B

trim ϐ


ltrim

̑ÕXy[X菜܂B
ʂ͓nϐɊi[܂B

ltrim ϐ


rtrim

̌̃Xy[X菜܂B
ʂ͓nϐɊi[܂B

rtrim ϐ


lcase

Shift_JIŜݑΉ
񒆂̕啶珬(Aa Zz)ɒu܂
ʂ͓nϐɊi[܂B

lcase ϐ


ucase

Shift_JIŜݑΉ
񒆂̕啶(aA zZ)ɒu܂
ʂ͓nϐɊi[܂B

ucase ϐ


left

̍w蕶؂o܂
ʂ͕ϐ left Ɋi[܂

left ϐ,N

N:؂o


right

̉Ew蕶؂o܂
ʂ͕ϐ right Ɋi[܂

right ϐ,N

N:؂o


̒u

replace ϐ,,u㕶

vO

str="abcdefghijklmn"
replace str,"def","XXXXX"
print str

s

$ ./basic test.txt
abcXXXXXghijklmn


ChJ[hǧ

match p^[,

p^[Ƃėp\ȃChJ[h
*    0ȏ̃ChJ[h
?    1̃ChJ[h(ShiftJis2oCg1ƂĈ܂)
[]   JbR̈ꕶɃ}b`
     擪ȊOɏꂽ'-'͕͈̔͂\
     [0-9]Ȃ[0123456789]ƓBAShiftJis QoCgԂł-͎sB

\\   ̕GXP[v
\\\\  \
\\*   *
\\?   ?
\\[   [
\\]   ]

ʂ͕ϐ match Ɋi[܂B


vO

str="abcdefg*?h\\i"

print str+"\n------------------"

match "b*f",str
print match

match "b???f",str
print match

match "b*???f",str
print match

match "\\*",str
print match

match "\\?",str
print match

match "?\\\\?",str
print match

match "?[c-g]?",str
print match

match "?[0-9c-g]?",str
print match


s

$ ./basic test.txt
abcdefg*?h\i
------------------
bcdef
bcdef
bcdef
*
?
h\i
bcd
bcd


񒆂̉pJi(Sp̔p)ϊ
Shift_JIŜݑΉ
ϐ̒lڕύX܂B

pSp
jis ϐ

Spp
asc ϐ


̌

instr Ώە,

񂪌ꍇɂ͕ϐ instr ɐ擪̕ʒuԂĂ܂
Ȃꍇinstr0܂


vO

str="atest"
instr str,"test"
print instr


s

$ ./basic test.txt
2


tH[}bgɏ]̐`

format tH[}bg,

ʂ͕ϐ format Ɋi[܂B


tH[}bg

0-9 A-Z a-z ϊΏۂ̕ꍇA̕Kp
# ϊΏۂ̕ꍇɂ͕KpȂ
ȊO͑̕āAϊꂸɓKpB


vO

i=12345
str i		'𕶎ɕϊ
format "###,###,###",i
print format
'o͌ : 12,345

format "0000","123456"
print format
'o͌ : 3456

format "0000","99"
print format
'o͌ : 0099

format "ABCD","XX"
print format
'o͌ : ABXX

format "AB-CD","123"
print format
'o͌ : A1-23

format "##","1234"
print format
'o͌ : 34

format "##-##-##","1234"
print format
'o͌ : 12-34


t@Cǂݍ

fread z,t@C

t@C̓esƂɔzɓǂݍ܂܂
ǂݍ񂾌͕ϐ fread Ɋi[܂B
G[ɂ́Aϐ fread -1i[܂B


t@C ./a.txt ǂݍݓe\vO

fread ar,"./a.txt"
if fread==-1 then end'ǂݍ݃G[̏ꍇɂ

for i=1 to fread
	print ar[i]
next i


t@C

fwrite z,t@C,z̒

z̐擪璷At@Cɏ܂܂
G[ɂ́Aϐ fwrite -1i[܂B

vO

ar[1]="hello"
ar[2]="test"
ar[4]=0
ar[5]=100
fwrite ar,"a.txt",5

s
t@C a.txt ̓e

hello
test

0
100


t@C̒ǋL
ǂݍ݌Azvf₵ďނƂɂt@CɒǋLł܂B
̗ł͕ test ǋL܂B

fread ar,"a.txt"
ar[fread+1]="test"
fwrite ar,"a.txt",fread+1


eval
̖߂s܂
1sŊ閽߂̂ݎs\ł
goto֐AȂǂ͎s\łA߂sɓnfor - nextȂǂ͎sł܂B
1sifł͎gpł܂	:C^v^ł͖߂sPʂŏA1sPʂōlifɂ̖߂s邽߂łB

eval "print \"test\""



a="print \"test\""
eval a

Lł print "test" ̈sƓłB


import

import߂̓C^v^\[XǂݍݎɁA
w̃t@Ceƒu܂B
vOœIȏ͂ł܂B

import t@C

import ./test.txt









